package com.heima.comment.controller;

import com.heima.comment.service.ICommentService;
import com.heima.model.comment.dtos.CommentDto;
import com.heima.model.comment.dtos.CommentLikeDto;
import com.heima.model.comment.dtos.CommentSaveDto;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/api/v1/comment")
public class CommentController {

    @Resource
    private ICommentService commentService;

    @PostMapping("/save")
    public ResponseResult saveComment(@RequestBody CommentSaveDto dto) {
        log.info("评论内容：{}", dto.getContent());
        log.info("文章ID：{}", dto.getArticleId());
        return commentService.saveComment(dto);
    }

    @PostMapping("/load")
    public ResponseResult loadComment(@RequestBody CommentDto dto) {
        log.info("文章ID：{}", dto.getArticleId());
        log.info("最小日期：{}", dto.getMinDate());
        return commentService.loadComment(dto);
    }

    @PostMapping("/like")
    public ResponseResult likeComment(@RequestBody CommentLikeDto dto) {
        log.info("评论id：{}", dto.getCommentId());
        log.info("操作：{}", dto.getOperation());
        return commentService.likeComment(dto);
    }

}
